//
//  BkMoneyBackViewController.m
//  TuDianEducation
//
//  Created by lixinkeji on 2021/1/9.
//  Copyright © 2021 zhangbenchao. All rights reserved.
//

#import "BkMoneyBackViewController.h"
#import "BkMoneyBackView.h"
#import "CommitSucessViewController.h"
@interface BkMoneyBackViewController ()
@property (nonatomic,strong) BkMoneyBackView *headerView;
@property (nonatomic,strong) UITableView *tableView;
@end

@implementation BkMoneyBackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.tableView];
    self.title = @"退款/售后";
    double value = 0.0f;
    for (NSDictionary *dic in self.dataArray) {
        value += [dic[@"gprice"] doubleValue] *[dic[@"gnum"] doubleValue] ;
    }
    _headerView.dataArray = self.dataArray;
    _headerView.money = value;
}
-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(TSScaleW(0), 0, TSScreenWidth, TSScreenHeight - Height_NavBar) style:(UITableViewStyleGrouped)];
        
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

        _tableView.tableHeaderView = self.headerView;
        if (@available(iOS 11.0, *))
        {
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            _tableView.estimatedRowHeight = 0;
            _tableView.estimatedSectionHeaderHeight = 0;
            _tableView.estimatedSectionFooterHeight = 0;
        }
        else
        {
            self.automaticallyAdjustsScrollViewInsets = NO;
        }
       
    }
    return _tableView;
}

-(BkMoneyBackView *)headerView{
    if (!_headerView) {
        _headerView = [[BkMoneyBackView alloc]init];
        WS(weakSelf);
        
        _headerView.callBackBlock = ^{
            if ([weakSelf pamasIsOkOrNot]) {
                [weakSelf requstorderrefundWithoid];
            }
        };
    }
    return _headerView;
}

-(BOOL)pamasIsOkOrNot{
   
       if (!self.headerView.refundreason.length) {
          // [SSTool error:SSKJLanguage(@"请输入您的手机号")];
           [MBProgressHUD showError:@"请输入退款原因"];
           return NO;
       }

    return YES;
}
///退款
-(void)requstorderrefundWithoid
{
    NSDictionary *pamas = @{@"ordernum":_ordernum,@"odidlist":_odidlist,@"refundreason":self.headerView.refundreason,@"refunddesc":self.headerView.refunddesc,@"refundimage":self.headerView.urlsString};
   // [MBProgressHUD showHUDAddedTo:self.view animated:YES];
       [NetWorkTools postConJSONWithUrl:@"orderrefund" parameters:pamas success:^(id responseObject) {
           NSString *result = responseObject[@"result"];
           NSString *resultNote = responseObject[@"resultNote"];
          

           if (result.integerValue == 0) {
               CommitSucessViewController *vc = [[CommitSucessViewController alloc]init];
               [self.navigationController pushViewController:vc animated:YES];
               vc.callBackBlock = ^{
                   [self.navigationController popViewControllerAnimated:YES];
               };
           }else{
               
           }
           [MBProgressHUD showError:resultNote];
           

       } fail:^(NSError *error) {

       }];
}
@end
